<template>
  <div>
    <span class="search-condition-item-label"
          :title="attr.title">{{ attr.title ? attr.title : '' }}</span>
    <a-radio-group class="search-condition-item-widget"
                   :value="newValue"
                   @change="onValueChange">
      <a-radio v-for="item in attr.items"
               :value="item.value"
               :disabled="getRadioDisabled(item)"
               :key="item.value"> {{ item.title }} </a-radio>
    </a-radio-group>
  </div>
</template>

<script>
  export default {
    props: {
      attr: {
        type: Object,
        default: {
          title: '',
          items: []
        }
      },
      value: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        newValue: this.value
      };
    },
    watch: {
      value(newVal, oldVal) {
        this.newValue = newVal;
      }
    },
    methods: {
      getRadioDisabled(item) {
        if (this.attr.disabled || item.disabled) {
          return true;
        } else {
          return false;
        }
      },
      onValueChange(e) {
        const value = e.target.value;
        if (this.newValue != value) {
          // this.newValue = value;
          this.$emit('valueChange', { key: this.attr.key, value: value });
        }
      }
    }
  };
</script>
<style lang="scss">
  .search-condition-item-widget {
    .ant-radio-wrapper {
      margin-right: 0px;
      span.ant-radio + * {
        padding-left: 4px;
      }
    }
  }
</style>

<style scoped>
  .search-condition-item-widget {
    text-align: left;
  }
</style>



